# Maintainer:
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: BlackEagle < ike DOT devolder AT gmail DOT com >
# Contributor: Preecha Patumchareonpol <yumyai at gmail.com> 

pkgname=podofo-0.9
_pkgname=podofo
pkgver=0.9.8
pkgrel=5
pkgdesc="A C++ library to work with the PDF file format (legacy version)"
arch=('loong64' 'x86_64')
url="http://podofo.sourceforge.net"
license=('GPL')
depends=('openssl' 'fontconfig' 'libtiff' 'libidn' 'libjpeg-turbo' 'libunistring')
makedepends=('cmake')
source=("https://downloads.sourceforge.net/${_pkgname}/${_pkgname}-${pkgver}.tar.gz"
         https://github.com/podofo/podofo/commit/23d26f39.patch)
sha256sums=('5de607e15f192b8ad90738300759d88dea0f5ccdce3bf00048a0c932bc645154'
            '29486f35f5bc9e4b996bc66795e2e664e051d8cbe53a3cf4957658cae80914cc')

prepare() {
# Don't hardcode install dirs
  patch -d ${_pkgname}-${pkgver} -p1 < 23d26f39.patch
# Fix include dir in pc file
  sed -e 's|@CMAKE_INSTALL_FULL_INCLUDEDIR@/podofo|@CMAKE_INSTALL_FULL_INCLUDEDIR@|' -i ${_pkgname}-${pkgver}/src/podofo/libpodofo.pc.in
}

build() {
  cmake -B build -S ${_pkgname}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib/podofo-0.9 \
    -DCMAKE_INSTALL_INCLUDEDIR=include/podofo-0.9 \
    -DFREETYPE_INCLUDE_DIR=/usr/include/freetype2 \
    -DPODOFO_BUILD_SHARED=1 \
    -DPODOFO_HAVE_JPEG_LIB=1 \
    -DPODOFO_HAVE_PNG_LIB=1 \
    -DPODOFO_HAVE_TIFF_LIB=1 \
    -DPODOFO_BUILD_LIB_ONLY=1
  cmake --build build
}

package() {
  DESTDIR="${pkgdir}" cmake --install build
  ln -rs "$pkgdir"/usr/lib/podofo-0.9/libpodofo.so.0.9.8 "$pkgdir"/usr/lib
}
